package interview;

/**
 * 一个数组，每个元素都大于0，可以将一些元素修改为负数，使数组和趋近于0. 问最接近0的是多少
 *
 * @author zhangjie
 */
public class NearZeroTest {

  private static Integer near = Integer.MAX_VALUE;

  public static void main(String[] args) {
    int[] nums = new int[]{2, 3, 4};
    dfs(nums, 0, 0);
    System.out.println(near);

    //dp



  }

  public static void dfs(int[] nums, int index, int sum) {
    if (index == nums.length) {
      near = Math.min(near, Math.abs(sum));
      return;
    }
    dfs(nums, index + 1, sum + nums[index]);
    dfs(nums, index + 1, sum - nums[index]);
  }
}
